package cn.kgc.mcartoon.configration;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.stereotype.Component;

@Configuration
@Component
public class RedisConfigration {

    /**
     *  方法名作为对象名存入IOC容器
     */
    @Bean
    public RedisTemplate<Object, Object> jsonRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<Object, Object> template = new RedisTemplate();
        template.setDefaultSerializer(new Jackson2JsonRedisSerializer(Object.class) );
        template.setConnectionFactory(redisConnectionFactory);
        return template;
    }
}
